package com.teach.javafxclient.controller.base;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import kong.unirest.json.JSONObject;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class CourseTableDetailedController {
    @FXML
    private Label name;

    @FXML
    private Label teacherName;

    @FXML
    private Label location0;

    @FXML
    private Label credit;

    @FXML
    private Label courseId;

    @FXML
    private Label week;

    @FXML
    private Label assessment;

    @FXML
    private Label type;

    public void setCourseData(JSONObject courseData) {
        name.setText(courseData.getString("name"));
        teacherName.setText(courseData.getString("teacherName"));
        location0.setText(courseData.getString("location"));
        double credit0= Double.parseDouble(courseData.getString("credit"));
        BigDecimal credit1 = new BigDecimal(courseData.getString("credit"));
        credit1 = credit1.setScale(1, RoundingMode.HALF_UP);
        credit.setText(String.valueOf(credit1));
        courseId.setText(courseData.getString("courseId"));
        String assessmentValue = courseData.getString("assessment");
        if (assessmentValue.equals("GRADE")) {
            assessment.setText("考试");
        } else {
            assessment.setText("考核");
        }

        type.setText(courseData.getString("type"));

        JSONObject time = courseData.getJSONObject("time");
        int from = time.getInt("from");
        int to = time.getInt("to");
        String type = time.getString("type");
        String weekText = "第" + from + "-" + to + "周";
        if (type.equals("all")) {
            weekText += "，所有周";
        } else if (type.equals("odd")) {
            weekText += "，奇数周";
        } else if (type.equals("even")) {
            weekText += "，偶数周";
        }
        week.setText(weekText);
    }
}

